# compiler
CC = gcc
 
# sources
SRC = ./src
 
# objects
OBJ = ./obj
 
# headers
HDR = ./include
 
# binary
BIN = ./bin
 
# librarys
LIB = -ansi -lm -lpthread -lmysqlclient -lz -ldl

#dev flags
CFLAGS = -fPIC -pedantic -g -Wall -Wextra -O -Wwrite-strings -Wstrict-prototypes -Wuninitialized -DDEBUG_MODE -I$(HDR)
#-DUSE_SSL

# Parano mode (Doesn't work: check with -ED-)
#CFLAGS = -ansi -O2 -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int -Werror-implicit-function-declaration -Wmain -#Wparentheses -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused -Wuninitialized -Wunknown-pragmas -Wfloat-equal -#Wundef -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings -Wconversion -Wsign-compare -Waggregate-return -Wstrict-#prototypes -Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn -Wformat -Wmissing-format-attribute -Wno-deprecated-#declarations -Wpacked -Wredundant-decls -Wnested-externs -Winline -Wlong-long -Wunreachable-code -I$(HDR)


#release flags
#CFLAGS =  -O2 -I$(HDR)



SOURCES= $(wildcard $(SRC)/*.c)
 
# Convert $(SRC)/%.c to $(SRC)/%.o
OBJECTS2= $(SOURCES:.c=.o)
# Convert $(SRC)/%.o to %.o
OBJECTS1= $(notdir $(OBJECTS2))
# Convert %.o to $(OBJ)/%.o
OBJECTS= $(addprefix obj/, $(OBJECTS1))

all: $(BIN)/server

$(BIN)/server: $(OBJECTS)
	$(CC) -o $(BIN)/server $(OBJECTS) $(LIB)
 
$(OBJ)/%.o: $(SRC)/%.c
	$(CC)  $(CFLAGS) -o $@ -c $<

buildmods: 
	ar rcs $(OBJ)/aureslib.a $(OBJECTS)
	cd modules/ && make

cleanobj:
	rm -rf $(OBJ)/*

cleanmods:
	rm -rf $(BIN)/modules/*.so
 
clean: cleanobj cleanmods
	rm -rf $(BIN)/server
	 
depend:
	makedepend -I$(HDR) $(SRC)/*.c
